package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaDeviceType;
import com.sailfish.springbootdemo.service.db1.PcbaDeviceTypeService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pcbaDeviceType")
@CrossOrigin
public class PcbaDeviceTypeController {

    @Autowired
    private PcbaDeviceTypeService pcbaDeviceTypeService;

    @PostMapping("/getAllPcbaDeviceType")
    public Result getAllPcbaDeviceType(String searchValue, Integer isTechOwn) {
        try {
            return ResultUtil.success(pcbaDeviceTypeService.getAllPcbaDeviceType(searchValue, isTechOwn));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/getAllPcbaDeviceTypeWithPic")
    public Result getAllPcbaDeviceTypeWithPic(String searchValue, Integer isTechOwn) {
        try {
            return ResultUtil.success(pcbaDeviceTypeService.getAllPcbaDeviceTypeWithPic(searchValue, isTechOwn));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/deletePcbaDeviceType")
    public Result deletePcbaDeviceType(Integer pcbaDeviceTypeId) {
        return pcbaDeviceTypeService.deletePcbaDeviceType(pcbaDeviceTypeId);
    }

    @PostMapping("/addOrUpdatePcbaDeviceType")
    public Result addOrUpdatePcbaDeviceType(PcbaDeviceType pcbaDeviceType, String mode) {
        return pcbaDeviceTypeService.addOrUpdatePcbaDeviceType(pcbaDeviceType, mode);
    }

    @PostMapping("/getById")
    public Result getById(Integer pcbaDeviceTypeId) {
        try {
            if (pcbaDeviceTypeId == null || "".equals(pcbaDeviceTypeId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceTypeId", "Miss Param pcbaDeviceTypeId", null);
            }
            return ResultUtil.success(pcbaDeviceTypeService.getById(pcbaDeviceTypeId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }
}
